package hibernate;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * MyRole entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see hibernate.MyRole
 * @author MyEclipse Persistence Tools
 */

public class MyRoleDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory.getLogger(MyRoleDAO.class);
	// property constants
	public static final String ROLE_NAME = "roleName";
	public static final String ADD_ONE_USER_ABLE = "addOneUserAble";
	public static final String ADD_MANY_USERS_ABLE = "addManyUsersAble";
	public static final String DELETE_ONE_USER_ABLE = "deleteOneUserAble";
	public static final String DELETE_MANY_USERS_ABLE = "deleteManyUsersAble";
	public static final String MODIFY_USER_ABLE = "modifyUserAble";
	public static final String VIEW_USER_ABLE = "viewUserAble";
	public static final String ADD_ONE_HOUSE_ABLE = "addOneHouseAble";
	public static final String ADD_MANY_HOUSES_ABLE = "addManyHousesAble";
	public static final String DELETE_ONE_HOUSE_ABLE = "deleteOneHouseAble";
	public static final String DELETE_MANY_HOUSES_ABLE = "deleteManyHousesAble";
	public static final String MODIFY_HOUSE_ABLE = "modifyHouseAble";
	public static final String VIEW_HOUSE_ABLE = "viewHouseAble";
	public static final String ADD_ONE_ORDER_ABLE = "addOneOrderAble";
	public static final String ADD_MANY_ORDERS_ABLE = "addManyOrdersAble";
	public static final String DELETE_ONE_ORDER_ABLE = "deleteOneOrderAble";
	public static final String DELETE_MANY_ORDERS_ABLE = "deleteManyOrdersAble";
	public static final String MODIFY_ORDER_ABLE = "modifyOrderAble";
	public static final String VIEW_ORDER_ABLE = "viewOrderAble";
	public static final String TENANT_ABLE = "tenantAble";
	public static final String OWNER_ABLE = "ownerAble";
	public static final String COMMENT_ABLE = "commentAble";
	public static final String EXIT_HOUSE_ABLE = "exitHouseAble";

	protected void initDao() {
		// do nothing
	}

	public void save(MyRole transientInstance) {
		log.debug("saving MyRole instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MyRole persistentInstance) {
		log.debug("deleting MyRole instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MyRole findById(java.lang.Integer id) {
		log.debug("getting MyRole instance with id: " + id);
		try {
			MyRole instance = (MyRole) getHibernateTemplate().get(
					"hibernate.MyRole", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MyRole instance) {
		log.debug("finding MyRole instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MyRole instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MyRole as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByRoleName(Object roleName) {
		return findByProperty(ROLE_NAME, roleName);
	}

	public List findByAddOneUserAble(Object addOneUserAble) {
		return findByProperty(ADD_ONE_USER_ABLE, addOneUserAble);
	}

	public List findByAddManyUsersAble(Object addManyUsersAble) {
		return findByProperty(ADD_MANY_USERS_ABLE, addManyUsersAble);
	}

	public List findByDeleteOneUserAble(Object deleteOneUserAble) {
		return findByProperty(DELETE_ONE_USER_ABLE, deleteOneUserAble);
	}

	public List findByDeleteManyUsersAble(Object deleteManyUsersAble) {
		return findByProperty(DELETE_MANY_USERS_ABLE, deleteManyUsersAble);
	}

	public List findByModifyUserAble(Object modifyUserAble) {
		return findByProperty(MODIFY_USER_ABLE, modifyUserAble);
	}

	public List findByViewUserAble(Object viewUserAble) {
		return findByProperty(VIEW_USER_ABLE, viewUserAble);
	}

	public List findByAddOneHouseAble(Object addOneHouseAble) {
		return findByProperty(ADD_ONE_HOUSE_ABLE, addOneHouseAble);
	}

	public List findByAddManyHousesAble(Object addManyHousesAble) {
		return findByProperty(ADD_MANY_HOUSES_ABLE, addManyHousesAble);
	}

	public List findByDeleteOneHouseAble(Object deleteOneHouseAble) {
		return findByProperty(DELETE_ONE_HOUSE_ABLE, deleteOneHouseAble);
	}

	public List findByDeleteManyHousesAble(Object deleteManyHousesAble) {
		return findByProperty(DELETE_MANY_HOUSES_ABLE, deleteManyHousesAble);
	}

	public List findByModifyHouseAble(Object modifyHouseAble) {
		return findByProperty(MODIFY_HOUSE_ABLE, modifyHouseAble);
	}

	public List findByViewHouseAble(Object viewHouseAble) {
		return findByProperty(VIEW_HOUSE_ABLE, viewHouseAble);
	}

	public List findByAddOneOrderAble(Object addOneOrderAble) {
		return findByProperty(ADD_ONE_ORDER_ABLE, addOneOrderAble);
	}

	public List findByAddManyOrdersAble(Object addManyOrdersAble) {
		return findByProperty(ADD_MANY_ORDERS_ABLE, addManyOrdersAble);
	}

	public List findByDeleteOneOrderAble(Object deleteOneOrderAble) {
		return findByProperty(DELETE_ONE_ORDER_ABLE, deleteOneOrderAble);
	}

	public List findByDeleteManyOrdersAble(Object deleteManyOrdersAble) {
		return findByProperty(DELETE_MANY_ORDERS_ABLE, deleteManyOrdersAble);
	}

	public List findByModifyOrderAble(Object modifyOrderAble) {
		return findByProperty(MODIFY_ORDER_ABLE, modifyOrderAble);
	}

	public List findByViewOrderAble(Object viewOrderAble) {
		return findByProperty(VIEW_ORDER_ABLE, viewOrderAble);
	}

	public List findByTenantAble(Object tenantAble) {
		return findByProperty(TENANT_ABLE, tenantAble);
	}

	public List findByOwnerAble(Object ownerAble) {
		return findByProperty(OWNER_ABLE, ownerAble);
	}

	public List findByCommentAble(Object commentAble) {
		return findByProperty(COMMENT_ABLE, commentAble);
	}

	public List findByExitHouseAble(Object exitHouseAble) {
		return findByProperty(EXIT_HOUSE_ABLE, exitHouseAble);
	}

	public List findAll() {
		log.debug("finding all MyRole instances");
		try {
			String queryString = "from MyRole";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MyRole merge(MyRole detachedInstance) {
		log.debug("merging MyRole instance");
		try {
			MyRole result = (MyRole) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MyRole instance) {
		log.debug("attaching dirty MyRole instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MyRole instance) {
		log.debug("attaching clean MyRole instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static MyRoleDAO getFromApplicationContext(ApplicationContext ctx) {
		return (MyRoleDAO) ctx.getBean("MyRoleDAO");
	}
}